export default class KnightSprite extends godot.Sprite {
    frameStart = 10
    frameEnd = 19

    frameIndex = 0
    x = 200
    y = 200
    constructor(){
        super()

        //属性
        this.texture = godot.load("res://assets/knight.png") as godot.Texture
        this.position = new godot.Vector2(200,200)

        this.hframes = 10
        this.vframes = 2

        // this.frame = 10
        // this.frame_coords = new godot.Vector2(3,1)
        
        this.frameIndex = this.frameStart
        this.frame = this.frameIndex
    }

    _process(delta: number): void {
        // console.log("[Knight]process",delta)
        // 修改位置
        if(this.x < 800){
            this.x = this.x + 3
        }else{
            this.x = 200
        }
        this.position = new godot.Vector2(this.x,200)

        // 修改动画索引
        if(this.frameIndex < this.frameEnd){
            this.frameIndex = this.frameIndex + 0.1
        }else{
            this.frameIndex = this.frameStart
        }

        this.frame = Math.floor(this.frameIndex) 
    }

    _input(event: godot.InputEvent): void {
        // godot.print("KnightSpr",event)
    }
}